//
//  main.c
//  BLES
//
//  Created by Khalid on 03/12/2014.
//  Copyright (c) 2014 Khalid. All rights reserved.
//

#include "main.h"
#include "BLES6.h"
//#include <stdio.h>


//#include "ls_types.h"
//#include <stdio.h>
//#include <stdlib.h>
//#include <math.h>
//#include "EMatrix.h"
//#include "Numbering.h"
//#include "ABFG.h"
//#include "Solve.h"
//#include "Sens.h"
//#include "Levels.h"
//#include "Input.h"
//#include "Output.h"


//#include <stdlib.h>
//#include <math.h>

//#include "CExMinimiseCompliance.h"

// argv[1] = input file



int main(int argc, char *argv[]) //used to check compilation
//int initialize(int argc, char *argv) //Working with one function

{
    //printf("\n\n------*---Start of BLES Version 5.4 Program---*------\n");
    
    //int i,j,i2,j2,k,temp,temp2;	// incrementors
    //double ftemp;
    int i=0;
    /*----------------------------------------------------------------------------------/
     /																					/
     /		Read input file.															/
     /		Define: mesh, loads & BCs, level set, problem, controls, element matrices	/
     /																					/
     /----------------------------------------------------------------------------------*/
    
    // OLD WORKING CODE
//    char filename[100];
//    for(i=0;i<100;i++)
//    {
//        if(argv[1][i] == '.') {break;} // chop off file extension (if found)
//        else if(argv[1][i] == '\0'){break;}
//        else {filename[i] = argv[1][i];}
//    }
//    filename[i] = '\0';
//    
//    Solve(argv[1], filename);
    
    
    
//================== Fully working code ===========================
//    char filename[100];
//    for(i=0;i<100;i++)
//    {
//        if(argv[i] == '.') {break;} // chop off file extension (if found)
//        else if(argv[i] == '\0'){break;}
//        else {filename[i] = argv[i];}
//    }
//    filename[i] = '\0';
//    
//    Solve(argv, filename);
    
    
//================== Code for New trial ===========================
    
    int maxIteration = 0, itt = 0, convergence =0;
    
    //double *displacement;
    double *Py_disp; double *Py_alpha; int *Py_fixDof; double *Py_load;
    double *Py_Nsens; double *Py_disp; double *Py_alpha;
    
    maxIteration = initialise(i,argv[1]);
    
    // return control.maxItt from initialise
    
    do {
    
    analysis(itt,Py_disp,Py_alpha,Py_fixDof,Py_load);
    
    convergence = sensitivity(Py_Nsens,);
    
    if(convergence == 1) {break;}
    
    optimize();
    
    itt++;
        
    }while (itt < maxIteration); // automatically stop after max iterations
        
    output();
    
    return 0;
}







